package com.tencent.smtt.sdk;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.Signature;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.Process;
import android.text.TextUtils;
import android.util.Log;
import com.tencent.smtt.sdk.TbsDownloadConfig;
import com.tencent.smtt.sdk.TbsListener;
import com.tencent.smtt.utils.TbsLog;
import dalvik.system.DexClassLoader;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileLock;
import java.util.Properties;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import org.codehaus.jackson.util.MinimalPrettyPrinter;

/* loaded from: classes2.dex */
public class am {
    private static am d;
    private FileLock f;
    private FileOutputStream g;
    private static final ReentrantLock i = new ReentrantLock();
    private static final Lock j = new ReentrantLock();
    private static FileLock l = null;
    public static ThreadLocal<Integer> a = new an();
    private static Handler m = null;
    private static final Long[][] n = {new Long[]{44006L, 39094008L}, new Long[]{44005L, 39094008L}, new Long[]{43910L, 38917816L}, new Long[]{44027L, 39094008L}, new Long[]{44028L, 39094008L}, new Long[]{44029L, 39094008L}, new Long[]{44030L, 39094008L}, new Long[]{44032L, 39094008L}, new Long[]{44033L, 39094008L}, new Long[]{44034L, 39094008L}, new Long[]{43909L, 38917816L}};
    static boolean b = false;
    static final FileFilter c = new ao();
    private static int o = 0;
    private static boolean p = false;
    private int e = 0;
    private boolean h = false;
    private boolean k = false;

    private am() {
        if (m == null) {
            m = new ap(this, al.a().getLooper());
        }
    }

    private void A(Context context) {
        TbsLog.i("TbsInstaller", "TbsInstaller--generateNewTbsCoreFromUnzip");
        if (!z(context)) {
            TbsLog.i("TbsInstaller", "get rename fileLock#4 ## failed!");
            return;
        }
        try {
            C(context);
            D(context);
            TbsLog.i("TbsInstaller", "after renameTbsCoreShareDir");
            if (TbsShareManager.isThirdPartyApp(context)) {
                TbsLog.i("TbsInstaller", "is thirdapp and not chmod");
            } else {
                TbsLog.i("TbsInstaller", "prepare to shareTbsCore");
                TbsShareManager.a(context);
            }
            ai.a(context).a(0);
            ai.a(context).b(0);
            ai.a(context).d(0);
            ai.a(context).a("incrupdate_retry_num", 0);
            ai.a(context).b(0, 3);
            ai.a(context).a("");
            ai.a(context).c(-1);
            if (!TbsShareManager.isThirdPartyApp(context)) {
                int i2 = TbsDownloadConfig.getInstance(context).mPreferences.getInt(TbsDownloadConfig.TbsConfigKey.KEY_DECOUPLECOREVERSION, 0);
                if (i2 <= 0 || i2 == a().i(context) || i2 != a().j(context)) {
                    TbsLog.i("TbsInstaller", "TbsInstaller--generateNewTbsCoreFromUnzip #1 deCoupleCoreVersion is " + i2 + " getTbsCoreShareDecoupleCoreVersion is " + a().i(context) + " getTbsCoreInstalledVerInNolock is " + a().j(context));
                } else {
                    o(context);
                }
            }
            if (TbsShareManager.isThirdPartyApp(context)) {
                TbsShareManager.writeCoreInfoForThirdPartyApp(context, n(context), true);
            }
            a.set(0);
            o = 0;
        } catch (Throwable th) {
            th.printStackTrace();
            TbsLogReport a2 = TbsLogReport.a(context);
            a2.a(TbsListener.ErrorCode.RENAME_EXCEPTION, "exception when renameing from unzip:" + th.toString());
            TbsLog.e("TbsInstaller", "TbsInstaller--generateNewTbsCoreFromUnzip Exception", true);
        }
        g(context);
    }

    private void B(Context context) {
        TbsLog.i("TbsInstaller", "TbsInstaller--generateNewTbsCoreFromCopy");
        if (!z(context)) {
            TbsLog.i("TbsInstaller", "get rename fileLock#4 ## failed!");
            return;
        }
        try {
            C(context);
            E(context);
            TbsShareManager.a(context);
            ai.a(context).a(0, 3);
            if (!TbsShareManager.isThirdPartyApp(context)) {
                int i2 = TbsDownloadConfig.getInstance(context).mPreferences.getInt(TbsDownloadConfig.TbsConfigKey.KEY_DECOUPLECOREVERSION, 0);
                if (i2 <= 0 || i2 == a().i(context) || i2 != a().j(context)) {
                    TbsLog.i("TbsInstaller", "TbsInstaller--generateNewTbsCoreFromCopy #1 deCoupleCoreVersion is " + i2 + " getTbsCoreShareDecoupleCoreVersion is " + a().i(context) + " getTbsCoreInstalledVerInNolock is " + a().j(context));
                } else {
                    o(context);
                }
            }
            a.set(0);
        } catch (Exception e) {
            e.printStackTrace();
            TbsLogReport a2 = TbsLogReport.a(context);
            a2.a(TbsListener.ErrorCode.RENAME_EXCEPTION, "exception when renameing from copy:" + e.toString());
        }
        g(context);
    }

    private void C(Context context) {
        TbsLog.i("TbsInstaller", "TbsInstaller--deleteOldCore");
        com.tencent.smtt.utils.j.a(r(context), false);
    }

    private void D(Context context) {
        TbsLogReport a2;
        int i2;
        TbsLog.i("TbsInstaller", "TbsInstaller--renameShareDir");
        File u = u(context);
        File r = r(context);
        if (u == null || r == null) {
            return;
        }
        boolean renameTo = u.renameTo(r);
        if (context != null && TbsConfig.APP_WX.equals(context.getApplicationContext().getApplicationInfo().packageName)) {
            if (renameTo) {
                a2 = TbsLogReport.a(context);
                i2 = TbsListener.ErrorCode.RENAME_SUCCESS;
            } else {
                a2 = TbsLogReport.a(context);
                i2 = TbsListener.ErrorCode.RENAME_FAIL;
            }
            a2.a(i2, MinimalPrettyPrinter.DEFAULT_ROOT_VALUE_SEPARATOR);
        }
        g(context, false);
    }

    private void E(Context context) {
        TbsLog.i("TbsInstaller", "TbsInstaller--renameTbsCoreCopyDir");
        File w = w(context);
        File r = r(context);
        if (w == null || r == null) {
            return;
        }
        w.renameTo(r);
        g(context, false);
    }

    private void F(Context context) {
        TbsLog.i("TbsInstaller", "TbsInstaller--clearNewTbsCore");
        File u = u(context);
        if (u != null) {
            com.tencent.smtt.utils.j.a(u, false);
        }
        ai.a(context).b(0, 5);
        ai.a(context).c(-1);
        QbSdk.a(context, "TbsInstaller::clearNewTbsCore forceSysWebViewInner!");
    }

    public static synchronized am a() {
        am amVar;
        synchronized (am.class) {
            if (d == null) {
                synchronized (am.class) {
                    if (d == null) {
                        d = new am();
                    }
                }
            }
            amVar = d;
        }
        return amVar;
    }

    /* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:94:0x0092 -> B:116:0x00ac). Please submit an issue!!! */
    private void a(int i2, String str, Context context) {
        BufferedInputStream bufferedInputStream;
        BufferedOutputStream bufferedOutputStream;
        new File(str).delete();
        TbsLog.i("TbsInstaller", "Local tbs apk(" + str + ") is deleted!", true);
        File file = new File(context.getDir("tbs", 0), "core_unzip_tmp");
        if (file.canRead()) {
            File file2 = new File(file, "tbs.conf");
            Properties properties = new Properties();
            BufferedOutputStream bufferedOutputStream2 = null;
            try {
                try {
                    bufferedInputStream = new BufferedInputStream(new FileInputStream(file2));
                    try {
                        properties.load(bufferedInputStream);
                        bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(file2));
                    } catch (Throwable th) {
                        th = th;
                    }
                } catch (Throwable th2) {
                    th = th2;
                    bufferedInputStream = null;
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                properties.setProperty("tbs_local_installation", "true");
                properties.store(bufferedOutputStream, (String) null);
                TbsLog.i("TbsInstaller", "TBS_LOCAL_INSTALLATION is set!", true);
                try {
                    bufferedOutputStream.close();
                } catch (IOException e2) {
                    e2.printStackTrace();
                }
                bufferedInputStream.close();
            } catch (Throwable th3) {
                th = th3;
                bufferedOutputStream2 = bufferedOutputStream;
                try {
                    th.printStackTrace();
                    if (bufferedOutputStream2 != null) {
                        try {
                            bufferedOutputStream2.close();
                        } catch (IOException e3) {
                            e3.printStackTrace();
                        }
                    }
                    if (bufferedInputStream != null) {
                        bufferedInputStream.close();
                    }
                } catch (Throwable th4) {
                    if (bufferedOutputStream2 != null) {
                        try {
                            bufferedOutputStream2.close();
                        } catch (IOException e4) {
                            e4.printStackTrace();
                        }
                    }
                    if (bufferedInputStream != null) {
                        try {
                            bufferedInputStream.close();
                        } catch (IOException e5) {
                            e5.printStackTrace();
                        }
                    }
                    throw th4;
                }
            }
        }
    }

    public static void a(Context context) {
        String str;
        if (y(context)) {
            return;
        }
        if (d(context, "core_unzip_tmp")) {
            TbsCoreLoadStat.getInstance().a(context, TbsListener.ErrorCode.INFO_TEMP_CORE_EXIST_CONF_ERROR, new Throwable("TMP_TBS_UNZIP_FOLDER_NAME"));
            str = "TbsInstaller-UploadIfTempCoreExistConfError INFO_TEMP_CORE_EXIST_CONF_ERROR TMP_TBS_UNZIP_FOLDER_NAME";
        } else if (d(context, "core_share_backup_tmp")) {
            TbsCoreLoadStat.getInstance().a(context, TbsListener.ErrorCode.INFO_TEMP_CORE_EXIST_CONF_ERROR, new Throwable("TMP_BACKUP_TBSCORE_FOLDER_NAME"));
            str = "TbsInstaller-UploadIfTempCoreExistConfError INFO_TEMP_CORE_EXIST_CONF_ERROR TMP_BACKUP_TBSCORE_FOLDER_NAME";
        } else if (!d(context, "core_copy_tmp")) {
            return;
        } else {
            TbsCoreLoadStat.getInstance().a(context, TbsListener.ErrorCode.INFO_TEMP_CORE_EXIST_CONF_ERROR, new Throwable("TMP_TBS_COPY_FOLDER_NAME"));
            str = "TbsInstaller-UploadIfTempCoreExistConfError INFO_TEMP_CORE_EXIST_CONF_ERROR TMP_TBS_COPY_FOLDER_NAME";
        }
        TbsLog.e("TbsInstaller", str);
    }

    /* JADX WARN: Removed duplicated region for block: B:368:0x02fc A[Catch: all -> 0x04e2, Exception -> 0x04e6, TryCatch #15 {Exception -> 0x04e6, all -> 0x04e2, blocks: (B:327:0x0264, B:329:0x0270, B:331:0x0279, B:346:0x02d1, B:368:0x02fc, B:369:0x030a, B:371:0x030d, B:373:0x0319, B:375:0x0325, B:377:0x0331, B:379:0x0337, B:382:0x0344, B:385:0x0358, B:387:0x035e, B:388:0x037a, B:391:0x03ac, B:394:0x03c4, B:397:0x03ef, B:389:0x03a7, B:350:0x02d7, B:361:0x02f0, B:365:0x02f6), top: B:481:0x0264, inners: #3, #5 }] */
    /* JADX WARN: Removed duplicated region for block: B:393:0x03c2 A[ADDED_TO_REGION] */
    /* JADX WARN: Removed duplicated region for block: B:401:0x0402 A[Catch: Exception -> 0x0503, all -> 0x052b, TryCatch #9 {all -> 0x052b, blocks: (B:266:0x009f, B:268:0x00b9, B:271:0x00cf, B:273:0x00e9, B:276:0x0117, B:281:0x0127, B:288:0x0137, B:289:0x0140, B:291:0x0146, B:296:0x018b, B:298:0x0191, B:300:0x019e, B:303:0x01a5, B:308:0x01ca, B:310:0x01d4, B:313:0x01f2, B:314:0x01fa, B:316:0x0204, B:318:0x0211, B:322:0x021e, B:324:0x0251, B:325:0x0254, B:399:0x03f9, B:401:0x0402, B:403:0x0408, B:407:0x0415, B:408:0x041b, B:410:0x0427, B:411:0x042f, B:413:0x043c, B:415:0x045f, B:421:0x0489, B:422:0x04a1, B:416:0x0469, B:412:0x0433, B:427:0x04ae, B:432:0x04b7, B:431:0x04b4, B:433:0x04b8, B:449:0x0531, B:451:0x0548, B:455:0x0556, B:439:0x04ee, B:443:0x0509, B:319:0x0216), top: B:461:0x009f, inners: #10 }] */
    /* JADX WARN: Removed duplicated region for block: B:405:0x0410  */
    /* JADX WARN: Removed duplicated region for block: B:406:0x0413  */
    /* JADX WARN: Removed duplicated region for block: B:410:0x0427 A[Catch: Exception -> 0x0503, all -> 0x052b, TryCatch #9 {all -> 0x052b, blocks: (B:266:0x009f, B:268:0x00b9, B:271:0x00cf, B:273:0x00e9, B:276:0x0117, B:281:0x0127, B:288:0x0137, B:289:0x0140, B:291:0x0146, B:296:0x018b, B:298:0x0191, B:300:0x019e, B:303:0x01a5, B:308:0x01ca, B:310:0x01d4, B:313:0x01f2, B:314:0x01fa, B:316:0x0204, B:318:0x0211, B:322:0x021e, B:324:0x0251, B:325:0x0254, B:399:0x03f9, B:401:0x0402, B:403:0x0408, B:407:0x0415, B:408:0x041b, B:410:0x0427, B:411:0x042f, B:413:0x043c, B:415:0x045f, B:421:0x0489, B:422:0x04a1, B:416:0x0469, B:412:0x0433, B:427:0x04ae, B:432:0x04b7, B:431:0x04b4, B:433:0x04b8, B:449:0x0531, B:451:0x0548, B:455:0x0556, B:439:0x04ee, B:443:0x0509, B:319:0x0216), top: B:461:0x009f, inners: #10 }] */
    /* JADX WARN: Removed duplicated region for block: B:412:0x0433 A[Catch: Exception -> 0x0503, all -> 0x052b, TryCatch #9 {all -> 0x052b, blocks: (B:266:0x009f, B:268:0x00b9, B:271:0x00cf, B:273:0x00e9, B:276:0x0117, B:281:0x0127, B:288:0x0137, B:289:0x0140, B:291:0x0146, B:296:0x018b, B:298:0x0191, B:300:0x019e, B:303:0x01a5, B:308:0x01ca, B:310:0x01d4, B:313:0x01f2, B:314:0x01fa, B:316:0x0204, B:318:0x0211, B:322:0x021e, B:324:0x0251, B:325:0x0254, B:399:0x03f9, B:401:0x0402, B:403:0x0408, B:407:0x0415, B:408:0x041b, B:410:0x0427, B:411:0x042f, B:413:0x043c, B:415:0x045f, B:421:0x0489, B:422:0x04a1, B:416:0x0469, B:412:0x0433, B:427:0x04ae, B:432:0x04b7, B:431:0x04b4, B:433:0x04b8, B:449:0x0531, B:451:0x0548, B:455:0x0556, B:439:0x04ee, B:443:0x0509, B:319:0x0216), top: B:461:0x009f, inners: #10 }] */
    /* JADX WARN: Removed duplicated region for block: B:415:0x045f A[Catch: Exception -> 0x0503, all -> 0x052b, TryCatch #9 {all -> 0x052b, blocks: (B:266:0x009f, B:268:0x00b9, B:271:0x00cf, B:273:0x00e9, B:276:0x0117, B:281:0x0127, B:288:0x0137, B:289:0x0140, B:291:0x0146, B:296:0x018b, B:298:0x0191, B:300:0x019e, B:303:0x01a5, B:308:0x01ca, B:310:0x01d4, B:313:0x01f2, B:314:0x01fa, B:316:0x0204, B:318:0x0211, B:322:0x021e, B:324:0x0251, B:325:0x0254, B:399:0x03f9, B:401:0x0402, B:403:0x0408, B:407:0x0415, B:408:0x041b, B:410:0x0427, B:411:0x042f, B:413:0x043c, B:415:0x045f, B:421:0x0489, B:422:0x04a1, B:416:0x0469, B:412:0x0433, B:427:0x04ae, B:432:0x04b7, B:431:0x04b4, B:433:0x04b8, B:449:0x0531, B:451:0x0548, B:455:0x0556, B:439:0x04ee, B:443:0x0509, B:319:0x0216), top: B:461:0x009f, inners: #10 }] */
    /* JADX WARN: Removed duplicated region for block: B:416:0x0469 A[Catch: Exception -> 0x0503, all -> 0x052b, TRY_LEAVE, TryCatch #9 {all -> 0x052b, blocks: (B:266:0x009f, B:268:0x00b9, B:271:0x00cf, B:273:0x00e9, B:276:0x0117, B:281:0x0127, B:288:0x0137, B:289:0x0140, B:291:0x0146, B:296:0x018b, B:298:0x0191, B:300:0x019e, B:303:0x01a5, B:308:0x01ca, B:310:0x01d4, B:313:0x01f2, B:314:0x01fa, B:316:0x0204, B:318:0x0211, B:322:0x021e, B:324:0x0251, B:325:0x0254, B:399:0x03f9, B:401:0x0402, B:403:0x0408, B:407:0x0415, B:408:0x041b, B:410:0x0427, B:411:0x042f, B:413:0x043c, B:415:0x045f, B:421:0x0489, B:422:0x04a1, B:416:0x0469, B:412:0x0433, B:427:0x04ae, B:432:0x04b7, B:431:0x04b4, B:433:0x04b8, B:449:0x0531, B:451:0x0548, B:455:0x0556, B:439:0x04ee, B:443:0x0509, B:319:0x0216), top: B:461:0x009f, inners: #10 }] */
    /* JADX WARN: Removed duplicated region for block: B:466:0x02f0 A[EXC_TOP_SPLITTER, SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:470:0x04ae A[EXC_TOP_SPLITTER, SYNTHETIC] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    public void a(android.content.Context r22, android.content.Context r23, int r24) {
        /*
            Method dump skipped, instructions count: 1430
            To view this dump change 'Code comments level' option to 'DEBUG'
        */
        throw new UnsupportedOperationException("Method not decompiled: com.tencent.smtt.sdk.am.a(android.content.Context, android.content.Context, int):void");
    }

    private boolean a(Context context, File file, boolean z) {
        TbsDownloadConfig tbsDownloadConfig;
        int i2;
        TbsLog.i("TbsInstaller", "TbsInstaller-unzipTbs start");
        if (com.tencent.smtt.utils.j.c(file)) {
            boolean z2 = true;
            try {
                File dir = context.getDir("tbs", 0);
                File file2 = z ? new File(dir, "core_share_decouple") : new File(dir, "core_unzip_tmp");
                if (file2.exists() && TbsDownloadConfig.getInstance(context).mPreferences.getInt(TbsDownloadConfig.TbsConfigKey.KEY_DOWNLOADDECOUPLECORE, 0) != 1) {
                    com.tencent.smtt.utils.j.b(file2);
                }
            } catch (Throwable th) {
                TbsLog.e("TbsInstaller", "TbsInstaller-unzipTbs -- delete unzip folder if exists exception" + Log.getStackTraceString(th));
            }
            File v = z ? v(context) : u(context);
            if (v != null) {
                try {
                    com.tencent.smtt.utils.j.a(v);
                    if (z) {
                        com.tencent.smtt.utils.j.a(v, true);
                    }
                    boolean a2 = com.tencent.smtt.utils.j.a(file, v);
                    if (a2) {
                        a2 = a(v, context);
                    }
                    if (z) {
                        for (String str : v.list()) {
                            File file3 = new File(v, str);
                            if (file3.getName().endsWith(".dex")) {
                                file3.delete();
                            }
                        }
                        try {
                            new File(t(context), "x5.tbs").delete();
                        } catch (Exception unused) {
                        }
                    }
                    if (a2) {
                        g(context, true);
                        if (z) {
                            File q = q(context);
                            com.tencent.smtt.utils.j.a(q, true);
                            v.renameTo(q);
                            TbsShareManager.b(context);
                        }
                    } else {
                        com.tencent.smtt.utils.j.b(v);
                        TbsDownloadConfig.getInstance(context).setInstallInterruptCode(-522);
                        TbsLog.e("TbsInstaller", "copyFileIfChanged -- delete tmpTbsCoreUnzipDir#1! exist:" + v.exists());
                    }
                    return a2;
                } catch (IOException e) {
                    TbsDownloadConfig.getInstance(context).setInstallInterruptCode(-523);
                    TbsLogReport.a(context).a(TbsListener.ErrorCode.UNZIP_IO_ERROR, e);
                    if (((v == null || !v.exists()) ? false : false) && v != null) {
                        try {
                            com.tencent.smtt.utils.j.b(v);
                            TbsLog.e("TbsInstaller", "copyFileIfChanged -- delete tmpTbsCoreUnzipDir#2! exist:" + v.exists());
                        } catch (Throwable th2) {
                            TbsLog.e("TbsInstaller", "copyFileIfChanged -- delete tmpTbsCoreUnzipDir#2! exception:" + Log.getStackTraceString(th2));
                        }
                    }
                    return false;
                } catch (Exception e2) {
                    TbsDownloadConfig.getInstance(context).setInstallInterruptCode(-523);
                    TbsLogReport.a(context).a(TbsListener.ErrorCode.UNZIP_OTHER_ERROR, e2);
                    if (((v == null || !v.exists()) ? false : false) && v != null) {
                        try {
                            com.tencent.smtt.utils.j.b(v);
                            TbsLog.e("TbsInstaller", "copyFileIfChanged -- delete tmpTbsCoreUnzipDir#2! exist:" + v.exists());
                        } catch (Throwable th3) {
                            TbsLog.e("TbsInstaller", "copyFileIfChanged -- delete tmpTbsCoreUnzipDir#2! exception:" + Log.getStackTraceString(th3));
                        }
                    }
                    return false;
                } finally {
                    TbsLog.i("TbsInstaller", "TbsInstaller-unzipTbs done");
                }
            }
            TbsLogReport.a(context).a(TbsListener.ErrorCode.UNZIP_DIR_ERROR, "tmp unzip dir is null!");
            tbsDownloadConfig = TbsDownloadConfig.getInstance(context);
            i2 = -521;
        } else {
            TbsLogReport.a(context).a(TbsListener.ErrorCode.APK_INVALID, "apk is invalid!");
            tbsDownloadConfig = TbsDownloadConfig.getInstance(context);
            i2 = -520;
        }
        tbsDownloadConfig.setInstallInterruptCode(i2);
        return false;
    }

    /* JADX WARN: Removed duplicated region for block: B:125:0x0081  */
    /* JADX WARN: Removed duplicated region for block: B:164:0x0152 A[EXC_TOP_SPLITTER, SYNTHETIC] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    private boolean a(java.io.File r13, android.content.Context r14) {
        /*
            Method dump skipped, instructions count: 349
            To view this dump change 'Code comments level' option to 'DEBUG'
        */
        throw new UnsupportedOperationException("Method not decompiled: com.tencent.smtt.sdk.am.a(java.io.File, android.content.Context):boolean");
    }

    /* JADX WARN: Removed duplicated region for block: B:295:0x0461  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    public void b(android.content.Context r19, java.lang.String r20, int r21) {
        /*
            Method dump skipped, instructions count: 1548
            To view this dump change 'Code comments level' option to 'DEBUG'
        */
        throw new UnsupportedOperationException("Method not decompiled: com.tencent.smtt.sdk.am.b(android.content.Context, java.lang.String, int):void");
    }

    private boolean b(Context context, File file) {
        return a(context, file, false);
    }

    private boolean c(Context context, File file) {
        try {
            File[] listFiles = file.listFiles(new au(this));
            int length = listFiles.length;
            if (Build.VERSION.SDK_INT < 16 && context.getPackageName() != null && context.getPackageName().equalsIgnoreCase(TbsConfig.APP_DEMO)) {
                try {
                    Thread.sleep(5000L);
                } catch (Exception unused) {
                }
            }
            ClassLoader classLoader = context.getClassLoader();
            for (int i2 = 0; i2 < length; i2++) {
                TbsLog.i("TbsInstaller", "jarFile: " + listFiles[i2].getAbsolutePath());
                new DexClassLoader(listFiles[i2].getAbsolutePath(), file.getAbsolutePath(), null, classLoader);
            }
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            TbsLogReport.a(context).a(TbsListener.ErrorCode.DEXOPT_EXCEPTION, e.toString());
            TbsLog.i("TbsInstaller", "TbsInstaller-doTbsDexOpt done");
            return false;
        }
    }

    private boolean d(Context context, File file) {
        File[] listFiles;
        try {
            File file2 = new File(file, "tbs_sdk_extension_dex.jar");
            File file3 = new File(file, "tbs_sdk_extension_dex.dex");
            new DexClassLoader(file2.getAbsolutePath(), file.getAbsolutePath(), null, context.getClassLoader());
            String a2 = g.a(context, file3.getAbsolutePath());
            if (TextUtils.isEmpty(a2)) {
                TbsLogReport.a(context).a(TbsListener.ErrorCode.DEXOAT_EXCEPTION, "can not find oat command");
                return false;
            }
            for (File file4 : file.listFiles(new av(this))) {
                String substring = file4.getName().substring(0, file4.getName().length() - 4);
                Runtime.getRuntime().exec("/system/bin/dex2oat " + a2.replaceAll("tbs_sdk_extension_dex", substring) + " --dex-location=" + a().r(context) + File.separator + substring + ".jar").waitFor();
            }
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            TbsLogReport.a(context).a(TbsListener.ErrorCode.DEXOAT_EXCEPTION, e);
            return false;
        }
    }

    private static boolean d(Context context, String str) {
        String str2;
        File file = new File(context.getDir("tbs", 0), str);
        if (!file.exists()) {
            str2 = "TbsInstaller-isPrepareTbsCore, #1";
        } else if (new File(file, "tbs.conf").exists()) {
            TbsLog.i("TbsInstaller", "TbsInstaller-isPrepareTbsCore, #3");
            return true;
        } else {
            str2 = "TbsInstaller-isPrepareTbsCore, #2";
        }
        TbsLog.i("TbsInstaller", str2);
        return false;
    }

    private synchronized boolean d(Context context, boolean z) {
        TbsLog.i("TbsInstaller", "TbsInstaller-enableTbsCoreFromCopy");
        boolean z2 = false;
        if (x(context)) {
            ReentrantLock reentrantLock = i;
            boolean tryLock = reentrantLock.tryLock();
            TbsLog.i("TbsInstaller", "TbsInstaller-enableTbsCoreFromCopy Locked =" + tryLock);
            if (tryLock) {
                int b2 = ai.a(context).b("copy_status");
                int a2 = a(false, context);
                TbsLog.i("TbsInstaller", "TbsInstaller-enableTbsCoreFromCopy copyStatus =" + b2);
                TbsLog.i("TbsInstaller", "TbsInstaller-enableTbsCoreFromCopy tbsCoreInstalledVer =" + a2);
                if (b2 == 1) {
                    if (a2 == 0) {
                        TbsLog.i("TbsInstaller", "TbsInstaller-enableTbsCoreFromCopy tbsCoreInstalledVer = 0", true);
                    } else if (z) {
                        TbsLog.i("TbsInstaller", "TbsInstaller-enableTbsCoreFromCopy tbsCoreInstalledVer != 0", true);
                    }
                    B(context);
                    z2 = true;
                }
                reentrantLock.unlock();
            }
            b();
            return z2;
        }
        return false;
    }

    private boolean e(Context context, int i2) {
        File u;
        boolean z;
        TbsLog.i("TbsInstaller", "TbsInstaller-doTbsDexOpt start - dirMode: " + i2);
        boolean z2 = false;
        try {
            if (i2 != 0) {
                if (i2 == 1) {
                    u = w(context);
                } else if (i2 != 2) {
                    TbsLog.e("TbsInstaller", "doDexoptOrDexoat mode error: " + i2);
                    return false;
                } else {
                    u = r(context);
                }
            } else if (TbsDownloadConfig.getInstance(context).mPreferences.getInt(TbsDownloadConfig.TbsConfigKey.KEY_DOWNLOADDECOUPLECORE, 0) == 1) {
                return true;
            } else {
                u = u(context);
            }
            String property = System.getProperty("java.vm.version");
            z = property != null && property.startsWith("2");
            boolean z3 = Build.VERSION.SDK_INT == 23;
            boolean z4 = TbsDownloadConfig.getInstance(context).mPreferences.getBoolean(TbsDownloadConfig.TbsConfigKey.KEY_STOP_PRE_OAT, false);
            if (z && z3 && !z4) {
                z2 = true;
            }
        } catch (Exception e) {
            e.printStackTrace();
            TbsLogReport.a(context).a(TbsListener.ErrorCode.DEXOPT_EXCEPTION, e.toString());
        }
        if (z2 && d(context, u)) {
            TbsLog.i("TbsInstaller", "doTbsDexOpt -- doDexoatForArtVm");
            return true;
        } else if (!z) {
            TbsLog.i("TbsInstaller", "doTbsDexOpt -- doDexoptForDavlikVM");
            return c(context, u);
        } else {
            TbsLog.i("TbsInstaller", "doTbsDexOpt -- is ART mode, skip!");
            TbsLog.i("TbsInstaller", "TbsInstaller-doTbsDexOpt done");
            return true;
        }
    }

    private boolean e(Context context, String str) {
        PackageInfo packageInfo;
        try {
            packageInfo = context.getPackageManager().getPackageInfo(str, 0);
        } catch (PackageManager.NameNotFoundException unused) {
            packageInfo = null;
        }
        return packageInfo != null;
    }

    private synchronized boolean e(Context context, boolean z) {
        if (context != null) {
            if (TbsConfig.APP_WX.equals(context.getApplicationContext().getApplicationInfo().packageName)) {
                TbsLogReport.a(context).a(TbsListener.ErrorCode.INSTALL_FROM_UNZIP, MinimalPrettyPrinter.DEFAULT_ROOT_VALUE_SEPARATOR);
            }
        }
        TbsLog.i("TbsInstaller", "TbsInstaller-enableTbsCoreFromUnzip canRenameTmpDir =" + z);
        TbsLog.i("TbsInstaller", "Tbsinstaller enableTbsCoreFromUnzip #1 ");
        boolean z2 = false;
        try {
        } catch (Exception e) {
            QbSdk.a(context, "TbsInstaller::enableTbsCoreFromUnzip Exception: " + e);
            e.printStackTrace();
        }
        if (x(context)) {
            TbsLog.i("TbsInstaller", "Tbsinstaller enableTbsCoreFromUnzip #2 ");
            ReentrantLock reentrantLock = i;
            boolean tryLock = reentrantLock.tryLock();
            TbsLog.i("TbsInstaller", "TbsInstaller-enableTbsCoreFromUnzip locked=" + tryLock);
            if (tryLock) {
                try {
                    int c2 = ai.a(context).c();
                    TbsLog.i("TbsInstaller", "TbsInstaller-enableTbsCoreFromUnzip installStatus=" + c2);
                    int a2 = a(false, context);
                    if (c2 == 2) {
                        TbsLog.i("TbsInstaller", "Tbsinstaller enableTbsCoreFromUnzip #4 ");
                        if (a2 == 0) {
                            TbsLog.i("TbsInstaller", "TbsInstaller-enableTbsCoreFromUnzip tbsCoreInstalledVer = 0", false);
                        } else if (z) {
                            TbsLog.i("TbsInstaller", "TbsInstaller-enableTbsCoreFromUnzip tbsCoreInstalledVer != 0", false);
                        }
                        A(context);
                        z2 = true;
                    }
                    reentrantLock.unlock();
                } catch (Throwable th) {
                    i.unlock();
                    throw th;
                }
            }
            b();
            return z2;
        }
        return false;
    }

    private Context f(Context context, int i2) {
        Context a2;
        TbsLog.i("TbsInstaller", "TbsInstaller--getTbsCoreHostContext tbsCoreTargetVer=" + i2);
        if (i2 <= 0) {
            return null;
        }
        String[] coreProviderAppList = TbsShareManager.getCoreProviderAppList();
        for (int i3 = 0; i3 < coreProviderAppList.length; i3++) {
            if (!context.getPackageName().equalsIgnoreCase(coreProviderAppList[i3]) && e(context, coreProviderAppList[i3]) && (a2 = a(context, coreProviderAppList[i3])) != null) {
                if (f(a2)) {
                    int j2 = j(a2);
                    TbsLog.i("TbsInstaller", "TbsInstaller-getTbsCoreHostContext hostTbsCoreVer=" + j2);
                    if (j2 != 0 && j2 == i2) {
                        TbsLog.i("TbsInstaller", "TbsInstaller-getTbsCoreHostContext targetApp=" + coreProviderAppList[i3]);
                        return a2;
                    }
                } else {
                    TbsLog.e("TbsInstaller", "TbsInstaller--getTbsCoreHostContext " + coreProviderAppList[i3] + " illegal signature go on next");
                }
            }
        }
        return null;
    }

    private synchronized boolean f(Context context, boolean z) {
        return false;
    }

    private void g(Context context, boolean z) {
        if (context == null) {
            TbsLogReport.a(context).a(TbsListener.ErrorCode.CREATE_TEMP_CONF_ERROR, "setTmpFolderCoreToRead context is null");
            return;
        }
        try {
            File file = new File(context.getDir("tbs", 0), "tmp_folder_core_to_read.conf");
            if (!z) {
                com.tencent.smtt.utils.j.b(file);
            } else if (!file.exists()) {
                file.createNewFile();
            }
        } catch (Exception e) {
            TbsLogReport a2 = TbsLogReport.a(context);
            a2.a(TbsListener.ErrorCode.CREATE_TEMP_CONF_ERROR, "setTmpFolderCoreToRead Exception message is " + e.getMessage() + " Exception cause is " + e.getCause());
        }
    }

    public static File t(Context context) {
        File file = new File(context.getDir("tbs", 0), "core_private");
        if (file.isDirectory() || file.mkdir()) {
            return file;
        }
        return null;
    }

    private static boolean y(Context context) {
        String str;
        if (context == null) {
            str = "TbsInstaller-getTmpFolderCoreToRead, #1";
        } else {
            try {
                if (new File(context.getDir("tbs", 0), "tmp_folder_core_to_read.conf").exists()) {
                    TbsLog.i("TbsInstaller", "TbsInstaller-getTmpFolderCoreToRead, #2");
                    return true;
                }
                TbsLog.i("TbsInstaller", "TbsInstaller-getTmpFolderCoreToRead, #3");
                return false;
            } catch (Exception unused) {
                str = "TbsInstaller-getTmpFolderCoreToRead, #4";
            }
        }
        TbsLog.i("TbsInstaller", str);
        return true;
    }

    private boolean z(Context context) {
        boolean z;
        TbsLog.i("TbsInstaller", "Tbsinstaller getTbsCoreRenameFileLock #1 ");
        try {
            z = TbsDownloadConfig.getInstance().getTbsCoreLoadRenameFileLockEnable();
        } catch (Throwable unused) {
            z = true;
        }
        TbsLog.i("TbsInstaller", "Tbsinstaller getTbsCoreRenameFileLock #2  enabled is " + z);
        l = !z ? bt.a().b(context) : com.tencent.smtt.utils.j.f(context);
        if (l == null) {
            TbsLog.i("TbsInstaller", "getTbsCoreRenameFileLock## failed!");
            return false;
        }
        TbsLog.i("TbsInstaller", "Tbsinstaller getTbsCoreRenameFileLock true ");
        return true;
    }

    public int a(String str) {
        if (str == null) {
            return 0;
        }
        BufferedInputStream bufferedInputStream = null;
        try {
            File file = new File(new File(str), "tbs.conf");
            if (file.exists()) {
                Properties properties = new Properties();
                BufferedInputStream bufferedInputStream2 = new BufferedInputStream(new FileInputStream(file));
                try {
                    properties.load(bufferedInputStream2);
                    bufferedInputStream2.close();
                    String property = properties.getProperty("tbs_core_version");
                    if (property == null) {
                        try {
                            bufferedInputStream2.close();
                        } catch (IOException unused) {
                        }
                        return 0;
                    }
                    int parseInt = Integer.parseInt(property);
                    try {
                        bufferedInputStream2.close();
                    } catch (IOException unused2) {
                    }
                    return parseInt;
                } catch (Exception unused3) {
                    bufferedInputStream = bufferedInputStream2;
                    if (bufferedInputStream != null) {
                        try {
                            bufferedInputStream.close();
                        } catch (IOException unused4) {
                        }
                    }
                    return 0;
                } catch (Throwable th) {
                    th = th;
                    bufferedInputStream = bufferedInputStream2;
                    if (bufferedInputStream != null) {
                        try {
                            bufferedInputStream.close();
                        } catch (IOException unused5) {
                        }
                    }
                    throw th;
                }
            }
            return 0;
        } catch (Exception unused6) {
        } catch (Throwable th2) {
            th = th2;
        }
    }

    public int a(boolean z, Context context) {
        if (z || a.get().intValue() <= 0) {
            a.set(Integer.valueOf(j(context)));
        }
        return a.get().intValue();
    }

    Context a(Context context, String str) {
        try {
            return context.createPackageContext(str, 2);
        } catch (Exception unused) {
            return null;
        }
    }

    public void a(Context context, int i2) {
        g(context, true);
        ai.a(context).b(i2, 2);
    }

    void a(Context context, Bundle bundle) {
        if (bundle == null || context == null) {
            return;
        }
        Object[] objArr = {context, bundle};
        Message message = new Message();
        message.what = 3;
        message.obj = objArr;
        m.sendMessage(message);
    }

    public void a(Context context, String str, int i2) {
        TbsLog.i("TbsInstaller", "TbsInstaller-installTbsCore tbsApkPath=" + str);
        TbsLog.i("TbsInstaller", "TbsInstaller-installTbsCore tbsCoreTargetVer=" + i2);
        TbsLog.i("TbsInstaller", "TbsInstaller-continueInstallTbsCore currentProcessName=" + context.getApplicationInfo().processName);
        TbsLog.i("TbsInstaller", "TbsInstaller-installTbsCore currentProcessId=" + Process.myPid());
        TbsLog.i("TbsInstaller", "TbsInstaller-installTbsCore currentThreadName=" + Thread.currentThread().getName());
        Object[] objArr = {context, str, Integer.valueOf(i2)};
        Message message = new Message();
        message.what = 1;
        message.obj = objArr;
        m.sendMessage(message);
    }

    public void a(Context context, boolean z) {
        int c2;
        int b2;
        String d2;
        int c3;
        int b3;
        boolean z2 = true;
        if (z) {
            this.k = true;
        }
        TbsLog.i("TbsInstaller", "TbsInstaller-continueInstallTbsCore currentProcessName=" + context.getApplicationInfo().processName);
        TbsLog.i("TbsInstaller", "TbsInstaller-continueInstallTbsCore currentProcessId=" + Process.myPid());
        TbsLog.i("TbsInstaller", "TbsInstaller-continueInstallTbsCore currentThreadName=" + Thread.currentThread().getName());
        if (x(context)) {
            ReentrantLock reentrantLock = i;
            if (reentrantLock.tryLock()) {
                try {
                    c2 = ai.a(context).c();
                    b2 = ai.a(context).b();
                    d2 = ai.a(context).d("install_apk_path");
                    c3 = ai.a(context).c("copy_core_ver");
                    b3 = ai.a(context).b("copy_status");
                    reentrantLock.unlock();
                } catch (Throwable th) {
                    i.unlock();
                    throw th;
                }
            } else {
                d2 = null;
                c2 = -1;
                b2 = 0;
                c3 = 0;
                b3 = -1;
            }
            b();
            TbsLog.i("TbsInstaller", "TbsInstaller-continueInstallTbsCore installStatus=" + c2);
            TbsLog.i("TbsInstaller", "TbsInstaller-continueInstallTbsCore tbsCoreInstallVer=" + b2);
            TbsLog.i("TbsInstaller", "TbsInstaller-continueInstallTbsCore tbsApkPath=" + d2);
            TbsLog.i("TbsInstaller", "TbsInstaller-continueInstallTbsCore tbsCoreCopyVer=" + c3);
            TbsLog.i("TbsInstaller", "TbsInstaller-continueInstallTbsCore copyStatus=" + b3);
            if (TbsShareManager.isThirdPartyApp(context)) {
                c(context, TbsShareManager.a(context, false));
                return;
            }
            int i2 = TbsDownloadConfig.getInstance(context).mPreferences.getInt(TbsDownloadConfig.TbsConfigKey.KEY_RESPONSECODE, 0);
            if (i2 != 1 && i2 != 2 && i2 != 4) {
                z2 = false;
            }
            if (!z2 && i2 != 0) {
                Bundle bundle = new Bundle();
                bundle.putInt("operation", 10001);
                a(context, bundle);
            }
            if (c2 > -1 && c2 < 2) {
                a(context, d2, b2);
            }
            if (b3 == 0) {
                b(context, c3);
            }
        }
    }

    public synchronized boolean a(Context context, Context context2) {
        TbsLog.i("TbsInstaller", "TbsInstaller--quickDexOptForThirdPartyApp");
        if (p) {
            return true;
        }
        p = true;
        new aq(this, context2, context).start();
        return true;
    }

    public boolean a(Context context, File file) {
        TbsLog.i("TbsInstaller", "unzipTbsCoreToThirdAppTmp #1");
        boolean a2 = a(context, file, false);
        TbsLog.i("TbsInstaller", "unzipTbsCoreToThirdAppTmp result is " + a2);
        return a2;
    }

    public boolean a(Context context, File[] fileArr) {
        return false;
    }

    int b(Context context, String str) {
        PackageInfo packageArchiveInfo = context.getPackageManager().getPackageArchiveInfo(str, 0);
        if (packageArchiveInfo != null) {
            return packageArchiveInfo.versionCode;
        }
        return 0;
    }

    public File b(Context context, Context context2) {
        File file = new File(context2.getDir("tbs", 0), "core_share");
        if (file.isDirectory() || ((context != null && TbsShareManager.isThirdPartyApp(context)) || file.mkdir())) {
            return file;
        }
        return null;
    }

    synchronized void b() {
        int i2 = this.e;
        this.e = i2 - 1;
        if (i2 <= 1 && this.h) {
            TbsLog.i("TbsInstaller", "releaseTbsInstallingFileLock without skip");
            com.tencent.smtt.utils.j.a(this.f, this.g);
            this.h = false;
            return;
        }
        TbsLog.i("TbsInstaller", "releaseTbsInstallingFileLock with skip");
    }

    public void b(Context context) {
        g(context, true);
        ai.a(context).b(i(context), 2);
    }

    /* JADX WARN: Removed duplicated region for block: B:271:0x023d  */
    /* JADX WARN: Removed duplicated region for block: B:273:0x0276  */
    /* JADX WARN: Removed duplicated region for block: B:304:0x036a  */
    /* JADX WARN: Removed duplicated region for block: B:309:0x03ac  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    public void b(android.content.Context r22, android.os.Bundle r23) {
        /*
            Method dump skipped, instructions count: 1012
            To view this dump change 'Code comments level' option to 'DEBUG'
        */
        throw new UnsupportedOperationException("Method not decompiled: com.tencent.smtt.sdk.am.b(android.content.Context, android.os.Bundle):void");
    }

    public void b(Context context, boolean z) {
        String str;
        TbsLog.i("TbsInstaller", "tryInstallTbsCore #1");
        if (QbSdk.b) {
            return;
        }
        if (Build.VERSION.SDK_INT < 8) {
            TbsLog.e("TbsInstaller", "android version < 2.1 no need install X5 core", true);
        } else if (y(context)) {
            TbsLog.i("TbsInstaller", "tryInstallTbsCore #2 ");
            if (d(context, "core_unzip_tmp") && e(context, z)) {
                str = "tryInstallTbsCore, enableTbsCoreFromUnzip!!";
            } else if (d(context, "core_share_backup_tmp") && f(context, z)) {
                str = "tryInstallTbsCore, enableTbsCoreFromBackup!!";
            } else if (!d(context, "core_copy_tmp") || !d(context, z)) {
                TbsLog.i("TbsInstaller", "tryInstallTbsCore, no need ", true);
                return;
            } else {
                str = "tryInstallTbsCore, enableTbsCoreFromCopy!!";
            }
            TbsLog.i("TbsInstaller", str, true);
        }
    }

    public boolean b(Context context, int i2) {
        if (TbsDownloader.getOverSea(context)) {
            return false;
        }
        TbsLog.i("TbsInstaller", "TbsInstaller-installLocalTbsCore targetTbsCoreVer=" + i2);
        TbsLog.i("TbsInstaller", "TbsInstaller-continueInstallTbsCore currentProcessName=" + context.getApplicationInfo().processName);
        TbsLog.i("TbsInstaller", "TbsInstaller-installLocalTbsCore currentProcessId=" + Process.myPid());
        TbsLog.i("TbsInstaller", "TbsInstaller-installLocalTbsCore currentThreadName=" + Thread.currentThread().getName());
        Context f = f(context, i2);
        if (f == null) {
            TbsLog.i("TbsInstaller", "TbsInstaller--installLocalTbsCore copy from null");
            return false;
        }
        Object[] objArr = {f, context, Integer.valueOf(i2)};
        Message message = new Message();
        message.what = 2;
        message.obj = objArr;
        m.sendMessage(message);
        return true;
    }

    public File c(Context context, Context context2) {
        File file = new File(context2.getDir("tbs", 0), "core_share_decouple");
        if (file.isDirectory() || ((context != null && TbsShareManager.isThirdPartyApp(context)) || file.mkdir())) {
            return file;
        }
        return null;
    }

    public String c(Context context, String str) {
        BufferedInputStream bufferedInputStream;
        BufferedInputStream bufferedInputStream2 = null;
        if (TextUtils.isEmpty(str)) {
            return null;
        }
        try {
            File file = new File(r(context), "tbs.conf");
            if (file.exists()) {
                Properties properties = new Properties();
                bufferedInputStream = new BufferedInputStream(new FileInputStream(file));
                try {
                    properties.load(bufferedInputStream);
                    bufferedInputStream.close();
                    String property = properties.getProperty(str);
                    try {
                        bufferedInputStream.close();
                    } catch (IOException unused) {
                    }
                    return property;
                } catch (Exception unused2) {
                    if (bufferedInputStream != null) {
                        try {
                            bufferedInputStream.close();
                        } catch (IOException unused3) {
                        }
                    }
                    return null;
                } catch (Throwable th) {
                    th = th;
                    bufferedInputStream2 = bufferedInputStream;
                    if (bufferedInputStream2 != null) {
                        try {
                            bufferedInputStream2.close();
                        } catch (IOException unused4) {
                        }
                    }
                    throw th;
                }
            }
            return null;
        } catch (Exception unused5) {
            bufferedInputStream = null;
        } catch (Throwable th2) {
            th = th2;
        }
    }

    void c(Context context, int i2) {
        int j2;
        TbsLog.i("TbsInstaller", "TbsInstaller-installTbsCoreForThirdPartyApp");
        if (i2 > 0 && (j2 = j(context)) != i2) {
            Context e = TbsShareManager.e(context);
            if (e != null || TbsShareManager.getHostCorePathAppDefined() != null) {
                TbsLog.i("TbsInstaller", "TbsInstaller--quickDexOptForThirdPartyApp hostContext != null");
                a(context, e);
            } else if (j2 <= 0) {
                TbsLog.i("TbsInstaller", "TbsInstaller--installTbsCoreForThirdPartyApp hostContext == null");
                QbSdk.a(context, "TbsInstaller::installTbsCoreForThirdPartyApp forceSysWebViewInner #2");
            }
        }
    }

    public void c(Context context, boolean z) {
        String str;
        File v;
        if (QbSdk.b) {
            return;
        }
        if (Build.VERSION.SDK_INT < 8) {
            TbsLog.e("TbsInstaller", "android version < 2.1 no need install X5 core", true);
            return;
        }
        try {
            if (!TbsShareManager.isThirdPartyApp(context) && (v = v(context)) != null && v.exists()) {
                com.tencent.smtt.utils.j.a(v, false);
                new File(t(context), "x5.tbs").delete();
            }
        } catch (Throwable unused) {
        }
        TbsLog.i("TbsInstaller", "Tbsinstaller installTbsCoreIfNeeded #1 ");
        if (y(context)) {
            TbsLog.i("TbsInstaller", "Tbsinstaller installTbsCoreIfNeeded #2 ");
            if (d(context, "core_unzip_tmp") && e(context, z)) {
                str = "TbsInstaller-installTbsCoreIfNeeded, enableTbsCoreFromUnzip!!";
            } else if (d(context, "core_share_backup_tmp") && f(context, z)) {
                str = "TbsInstaller-installTbsCoreIfNeeded, enableTbsCoreFromBackup!!";
            } else if (!d(context, "core_copy_tmp") || !d(context, z)) {
                TbsLog.i("TbsInstaller", "TbsInstaller-installTbsCoreIfNeeded, error !!", true);
                return;
            } else {
                str = "TbsInstaller-installTbsCoreIfNeeded, enableTbsCoreFromCopy!!";
            }
            TbsLog.i("TbsInstaller", str, true);
        }
    }

    public boolean c(Context context) {
        File file = new File(r(context), "tbs.conf");
        boolean z = false;
        if (!file.exists()) {
            return false;
        }
        Properties properties = new Properties();
        BufferedInputStream bufferedInputStream = null;
        try {
            BufferedInputStream bufferedInputStream2 = new BufferedInputStream(new FileInputStream(file));
            try {
                properties.load(bufferedInputStream2);
                boolean booleanValue = Boolean.valueOf(properties.getProperty("tbs_local_installation", "false")).booleanValue();
                if (booleanValue) {
                    try {
                        if (System.currentTimeMillis() - file.lastModified() > 259200000) {
                            z = true;
                        }
                    } catch (Throwable th) {
                        th = th;
                        z = booleanValue;
                        bufferedInputStream = bufferedInputStream2;
                        try {
                            th.printStackTrace();
                            return z;
                        } finally {
                            if (bufferedInputStream != null) {
                                try {
                                    bufferedInputStream.close();
                                } catch (IOException e) {
                                    e.printStackTrace();
                                }
                            }
                        }
                    }
                }
                TbsLog.i("TbsInstaller", "TBS_LOCAL_INSTALLATION is:" + booleanValue + " expired=" + z);
                boolean z2 = booleanValue & (!z);
                try {
                    bufferedInputStream2.close();
                    return z2;
                } catch (IOException e2) {
                    e2.printStackTrace();
                    return z2;
                }
            } catch (Throwable th2) {
                th = th2;
            }
        } catch (Throwable th3) {
            th = th3;
        }
    }

    public void d(Context context) {
        BufferedInputStream bufferedInputStream;
        BufferedOutputStream bufferedOutputStream;
        try {
            File file = new File(r(context), "tbs.conf");
            Properties properties = new Properties();
            BufferedOutputStream bufferedOutputStream2 = null;
            try {
                bufferedInputStream = new BufferedInputStream(new FileInputStream(file));
                try {
                    properties.load(bufferedInputStream);
                    bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(file));
                } catch (Throwable unused) {
                }
            } catch (Throwable unused2) {
                bufferedInputStream = null;
            }
            try {
                properties.setProperty("tbs_local_installation", "false");
                properties.store(bufferedOutputStream, (String) null);
                try {
                    bufferedOutputStream.close();
                } catch (IOException unused3) {
                }
            } catch (Throwable unused4) {
                bufferedOutputStream2 = bufferedOutputStream;
                if (bufferedOutputStream2 != null) {
                    try {
                        bufferedOutputStream2.close();
                    } catch (IOException unused5) {
                    }
                }
                if (bufferedInputStream == null) {
                    return;
                }
                bufferedInputStream.close();
            }
            bufferedInputStream.close();
        } catch (Throwable unused6) {
        }
    }

    public boolean d(Context context, int i2) {
        File r;
        String str;
        try {
            boolean isThirdPartyApp = TbsShareManager.isThirdPartyApp(context);
            if (!isThirdPartyApp) {
                r = r(context);
            } else if (!TbsShareManager.j(context)) {
                TbsLog.e("TbsInstaller", "321");
                return false;
            } else {
                r = new File(TbsShareManager.c(context));
                if (r.getAbsolutePath().contains(TbsConfig.APP_DEMO)) {
                    return true;
                }
            }
            if (r != null) {
                Long[][] lArr = n;
                int length = lArr.length;
                int i3 = 0;
                while (true) {
                    if (i3 >= length) {
                        break;
                    }
                    Long[] lArr2 = lArr[i3];
                    if (i2 == lArr2[0].intValue()) {
                        File file = new File(r, "libmttwebview.so");
                        if (file.exists() && file.length() == lArr2[1].longValue()) {
                            TbsLog.d("TbsInstaller", "check so success: " + i2 + "; file: " + file);
                        } else {
                            if (!isThirdPartyApp) {
                                com.tencent.smtt.utils.j.b(context.getDir("tbs", 0));
                            }
                            a.set(0);
                            str = "322";
                        }
                    } else {
                        i3++;
                    }
                }
                return true;
            }
            str = "323";
            TbsLog.e("TbsInstaller", str);
            return false;
        } catch (Throwable th) {
            TbsLog.e("TbsInstaller", "ISTBSCORELEGAL exception getMessage is " + th.getMessage());
            TbsLog.e("TbsInstaller", "ISTBSCORELEGAL exception getCause is " + th.getCause());
            return false;
        }
    }

    public boolean e(Context context) {
        try {
            File file = new File(com.tencent.smtt.utils.j.a(context, 4), "x5.tbs.decouple");
            File v = a().v(context);
            com.tencent.smtt.utils.j.a(v);
            com.tencent.smtt.utils.j.a(v, true);
            com.tencent.smtt.utils.j.a(file, v);
            for (String str : v.list()) {
                File file2 = new File(v, str);
                if (file2.getName().endsWith(".dex")) {
                    file2.delete();
                }
            }
            a().g(context, true);
            File q = q(context);
            com.tencent.smtt.utils.j.a(q, true);
            v.renameTo(q);
            TbsShareManager.b(context);
            return true;
        } catch (Exception unused) {
            return false;
        }
    }

    public boolean f(Context context) {
        if (TbsShareManager.getHostCorePathAppDefined() != null) {
            return true;
        }
        try {
            Signature signature = context.getPackageManager().getPackageInfo(context.getPackageName(), 64).signatures[0];
            if (context.getPackageName().equals(TbsConfig.APP_QB)) {
                if (!signature.toCharsString().equals("3082023f308201a8a00302010202044c46914a300d06092a864886f70d01010505003064310b30090603550406130238363110300e060355040813074265696a696e673110300e060355040713074265696a696e673110300e060355040a130754656e63656e74310c300a060355040b13035753443111300f0603550403130873616d75656c6d6f301e170d3130303732313036313835305a170d3430303731333036313835305a3064310b30090603550406130238363110300e060355040813074265696a696e673110300e060355040713074265696a696e673110300e060355040a130754656e63656e74310c300a060355040b13035753443111300f0603550403130873616d75656c6d6f30819f300d06092a864886f70d010101050003818d0030818902818100c209077044bd0d63ea00ede5b839914cabcc912a87f0f8b390877e0f7a2583f0d5933443c40431c35a4433bc4c965800141961adc44c9625b1d321385221fd097e5bdc2f44a1840d643ab59dc070cf6c4b4b4d98bed5cbb8046e0a7078ae134da107cdf2bfc9b440fe5cb2f7549b44b73202cc6f7c2c55b8cfb0d333a021f01f0203010001300d06092a864886f70d010105050003818100b007db9922774ef4ccfee81ba514a8d57c410257e7a2eba64bfa17c9e690da08106d32f637ac41fbc9f205176c71bde238c872c3ee2f8313502bee44c80288ea4ef377a6f2cdfe4d3653c145c4acfedbfbadea23b559d41980cc3cdd35d79a68240693739aabf5c5ed26148756cf88264226de394c8a24ac35b712b120d4d23a")) {
                    return false;
                }
            } else if (context.getPackageName().equals(TbsConfig.APP_WX)) {
                if (!signature.toCharsString().equals("308202eb30820254a00302010202044d36f7a4300d06092a864886f70d01010505003081b9310b300906035504061302383631123010060355040813094775616e67646f6e673111300f060355040713085368656e7a68656e31353033060355040a132c54656e63656e7420546563686e6f6c6f6779285368656e7a68656e2920436f6d70616e79204c696d69746564313a3038060355040b133154656e63656e74204775616e677a686f7520526573656172636820616e6420446576656c6f706d656e742043656e7465723110300e0603550403130754656e63656e74301e170d3131303131393134333933325a170d3431303131313134333933325a3081b9310b300906035504061302383631123010060355040813094775616e67646f6e673111300f060355040713085368656e7a68656e31353033060355040a132c54656e63656e7420546563686e6f6c6f6779285368656e7a68656e2920436f6d70616e79204c696d69746564313a3038060355040b133154656e63656e74204775616e677a686f7520526573656172636820616e6420446576656c6f706d656e742043656e7465723110300e0603550403130754656e63656e7430819f300d06092a864886f70d010101050003818d0030818902818100c05f34b231b083fb1323670bfbe7bdab40c0c0a6efc87ef2072a1ff0d60cc67c8edb0d0847f210bea6cbfaa241be70c86daf56be08b723c859e52428a064555d80db448cdcacc1aea2501eba06f8bad12a4fa49d85cacd7abeb68945a5cb5e061629b52e3254c373550ee4e40cb7c8ae6f7a8151ccd8df582d446f39ae0c5e930203010001300d06092a864886f70d0101050500038181009c8d9d7f2f908c42081b4c764c377109a8b2c70582422125ce545842d5f520aea69550b6bd8bfd94e987b75a3077eb04ad341f481aac266e89d3864456e69fba13df018acdc168b9a19dfd7ad9d9cc6f6ace57c746515f71234df3a053e33ba93ece5cd0fc15f3e389a3f365588a9fcb439e069d3629cd7732a13fff7b891499")) {
                    return false;
                }
            } else if (context.getPackageName().equals(TbsConfig.APP_QQ)) {
                if (!signature.toCharsString().equals("30820253308201bca00302010202044bbb0361300d06092a864886f70d0101050500306d310e300c060355040613054368696e61310f300d06035504080c06e58c97e4baac310f300d06035504070c06e58c97e4baac310f300d060355040a0c06e885bee8aeaf311b3019060355040b0c12e697a0e7babfe4b89ae58aa1e7b3bbe7bb9f310b30090603550403130251513020170d3130303430363039343831375a180f32323834303132303039343831375a306d310e300c060355040613054368696e61310f300d06035504080c06e58c97e4baac310f300d06035504070c06e58c97e4baac310f300d060355040a0c06e885bee8aeaf311b3019060355040b0c12e697a0e7babfe4b89ae58aa1e7b3bbe7bb9f310b300906035504031302515130819f300d06092a864886f70d010101050003818d0030818902818100a15e9756216f694c5915e0b529095254367c4e64faeff07ae13488d946615a58ddc31a415f717d019edc6d30b9603d3e2a7b3de0ab7e0cf52dfee39373bc472fa997027d798d59f81d525a69ecf156e885fd1e2790924386b2230cc90e3b7adc95603ddcf4c40bdc72f22db0f216a99c371d3bf89cba6578c60699e8a0d536950203010001300d06092a864886f70d01010505000381810094a9b80e80691645dd42d6611775a855f71bcd4d77cb60a8e29404035a5e00b21bcc5d4a562482126bd91b6b0e50709377ceb9ef8c2efd12cc8b16afd9a159f350bb270b14204ff065d843832720702e28b41491fbc3a205f5f2f42526d67f17614d8a974de6487b2c866efede3b4e49a0f916baa3c1336fd2ee1b1629652049")) {
                    return false;
                }
            } else if (context.getPackageName().equals(TbsConfig.APP_DEMO)) {
                if (!signature.toCharsString().equals("3082023f308201a8a00302010202044c46914a300d06092a864886f70d01010505003064310b30090603550406130238363110300e060355040813074265696a696e673110300e060355040713074265696a696e673110300e060355040a130754656e63656e74310c300a060355040b13035753443111300f0603550403130873616d75656c6d6f301e170d3130303732313036313835305a170d3430303731333036313835305a3064310b30090603550406130238363110300e060355040813074265696a696e673110300e060355040713074265696a696e673110300e060355040a130754656e63656e74310c300a060355040b13035753443111300f0603550403130873616d75656c6d6f30819f300d06092a864886f70d010101050003818d0030818902818100c209077044bd0d63ea00ede5b839914cabcc912a87f0f8b390877e0f7a2583f0d5933443c40431c35a4433bc4c965800141961adc44c9625b1d321385221fd097e5bdc2f44a1840d643ab59dc070cf6c4b4b4d98bed5cbb8046e0a7078ae134da107cdf2bfc9b440fe5cb2f7549b44b73202cc6f7c2c55b8cfb0d333a021f01f0203010001300d06092a864886f70d010105050003818100b007db9922774ef4ccfee81ba514a8d57c410257e7a2eba64bfa17c9e690da08106d32f637ac41fbc9f205176c71bde238c872c3ee2f8313502bee44c80288ea4ef377a6f2cdfe4d3653c145c4acfedbfbadea23b559d41980cc3cdd35d79a68240693739aabf5c5ed26148756cf88264226de394c8a24ac35b712b120d4d23a")) {
                    return false;
                }
            } else if (context.getPackageName().equals(TbsConfig.APP_QZONE)) {
                if (!signature.toCharsString().equals("308202ad30820216a00302010202044c26cea2300d06092a864886f70d010105050030819a310b3009060355040613023836311530130603550408130c4265696a696e672043697479311530130603550407130c4265696a696e67204369747931263024060355040a131d515a6f6e65205465616d206f662054656e63656e7420436f6d70616e7931183016060355040b130f54656e63656e7420436f6d70616e79311b301906035504031312416e64726f696420515a6f6e65205465616d301e170d3130303632373034303830325a170d3335303632313034303830325a30819a310b3009060355040613023836311530130603550408130c4265696a696e672043697479311530130603550407130c4265696a696e67204369747931263024060355040a131d515a6f6e65205465616d206f662054656e63656e7420436f6d70616e7931183016060355040b130f54656e63656e7420436f6d70616e79311b301906035504031312416e64726f696420515a6f6e65205465616d30819f300d06092a864886f70d010101050003818d003081890281810082d6aca037a9843fbbe88b6dd19f36e9c24ce174c1b398f3a529e2a7fe02de99c27539602c026edf96ad8d43df32a85458bca1e6fbf11958658a7d6751a1d9b782bf43a8c19bd1c06bdbfd94c0516326ae3cf638ac42bb470580e340c46e6f306a772c1ef98f10a559edf867f3f31fe492808776b7bd953b2cba2d2b2d66a44f0203010001300d06092a864886f70d0101050500038181006003b04a8a8c5be9650f350cda6896e57dd13e6e83e7f891fc70f6a3c2eaf75cfa4fc998365deabbd1b9092159edf4b90df5702a0d101f8840b5d4586eb92a1c3cd19d95fbc1c2ac956309eda8eef3944baf08c4a49d3b9b3ffb06bc13dab94ecb5b8eb74e8789aa0ba21cb567f538bbc59c2a11e6919924a24272eb79251677")) {
                    return false;
                }
            } else if (context.getPackageName().equals("com.tencent.qqpimsecure") && !signature.toCharsString().equals("30820239308201a2a00302010202044c96f48f300d06092a864886f70d01010505003060310b300906035504061302434e310b300906035504081302474431123010060355040713094775616e677a686f753110300e060355040a130754656e63656e74310b3009060355040b130233473111300f0603550403130857696c736f6e57753020170d3130303932303035343334335a180f32303635303632333035343334335a3060310b300906035504061302434e310b300906035504081302474431123010060355040713094775616e677a686f753110300e060355040a130754656e63656e74310b3009060355040b130233473111300f0603550403130857696c736f6e577530819f300d06092a864886f70d010101050003818d0030818902818100b56e79dbb1185a79e52d792bb3d0bb3da8010d9b87da92ec69f7dc5ad66ab6bfdff2a6a1ed285dd2358f28b72a468be7c10a2ce30c4c27323ed4edcc936080e5bedc2cbbca0b7e879c08a631182793f44bb3ea284179b263410c298e5f6831032c9702ba4a74e2ccfc9ef857f12201451602fc8e774ac59d6398511586c83d1d0203010001300d06092a864886f70d0101050500038181002475615bb65b8d8786b890535802948840387d06b1692ff3ea47ef4c435719ba1865b81e6bfa6293ce31747c3cd6b34595b485cc1563fd90107ba5845c28b95c79138f0dec288940395bc10f92f2b69d8dc410999deb38900974ce9984b678030edfba8816582f56160d87e38641288d8588d2a31e20b89f223d788dd35cc9c8")) {
                return false;
            }
            return true;
        } catch (Exception unused) {
            TbsLog.i("TbsInstaller", "TbsInstaller-installLocalTbsCore getPackageInfo fail");
            return false;
        }
    }

    public void g(Context context) {
        boolean z;
        FileLock fileLock;
        try {
            z = TbsDownloadConfig.getInstance().getTbsCoreLoadRenameFileLockEnable();
        } catch (Throwable unused) {
            z = true;
        }
        if (z && (fileLock = l) != null) {
            com.tencent.smtt.utils.j.a(context, fileLock);
        }
    }

    public int h(Context context) {
        BufferedInputStream bufferedInputStream = null;
        try {
            File u = u(context);
            TbsLog.i("TbsInstaller", "TbsInstaller--getTmpTbsCoreVersionUnzipDir  tbsShareDir is " + u);
            File file = new File(u, "tbs.conf");
            if (file.exists()) {
                Properties properties = new Properties();
                BufferedInputStream bufferedInputStream2 = new BufferedInputStream(new FileInputStream(file));
                try {
                    properties.load(bufferedInputStream2);
                    bufferedInputStream2.close();
                    String property = properties.getProperty("tbs_core_version");
                    if (property == null) {
                        try {
                            bufferedInputStream2.close();
                        } catch (IOException unused) {
                        }
                        return 0;
                    }
                    int parseInt = Integer.parseInt(property);
                    try {
                        bufferedInputStream2.close();
                    } catch (IOException unused2) {
                    }
                    return parseInt;
                } catch (Exception unused3) {
                    bufferedInputStream = bufferedInputStream2;
                    if (bufferedInputStream != null) {
                        try {
                            bufferedInputStream.close();
                        } catch (IOException unused4) {
                        }
                    }
                    return 0;
                } catch (Throwable th) {
                    th = th;
                    bufferedInputStream = bufferedInputStream2;
                    if (bufferedInputStream != null) {
                        try {
                            bufferedInputStream.close();
                        } catch (IOException unused5) {
                        }
                    }
                    throw th;
                }
            }
            return 0;
        } catch (Exception unused6) {
        } catch (Throwable th2) {
            th = th2;
        }
    }

    public int i(Context context) {
        BufferedInputStream bufferedInputStream = null;
        try {
            File file = new File(q(context), "tbs.conf");
            if (file.exists()) {
                Properties properties = new Properties();
                BufferedInputStream bufferedInputStream2 = new BufferedInputStream(new FileInputStream(file));
                try {
                    properties.load(bufferedInputStream2);
                    bufferedInputStream2.close();
                    String property = properties.getProperty("tbs_core_version");
                    if (property == null) {
                        try {
                            bufferedInputStream2.close();
                        } catch (IOException unused) {
                        }
                        return 0;
                    }
                    int parseInt = Integer.parseInt(property);
                    try {
                        bufferedInputStream2.close();
                    } catch (IOException unused2) {
                    }
                    return parseInt;
                } catch (Exception unused3) {
                    bufferedInputStream = bufferedInputStream2;
                    if (bufferedInputStream != null) {
                        try {
                            bufferedInputStream.close();
                        } catch (IOException unused4) {
                        }
                    }
                    return 0;
                } catch (Throwable th) {
                    th = th;
                    bufferedInputStream = bufferedInputStream2;
                    if (bufferedInputStream != null) {
                        try {
                            bufferedInputStream.close();
                        } catch (IOException unused5) {
                        }
                    }
                    throw th;
                }
            }
            return 0;
        } catch (Exception unused6) {
        } catch (Throwable th2) {
            th = th2;
        }
    }

    public int j(Context context) {
        BufferedInputStream bufferedInputStream = null;
        try {
            try {
                File file = new File(r(context), "tbs.conf");
                if (file.exists()) {
                    Properties properties = new Properties();
                    BufferedInputStream bufferedInputStream2 = new BufferedInputStream(new FileInputStream(file));
                    try {
                        properties.load(bufferedInputStream2);
                        bufferedInputStream2.close();
                        String property = properties.getProperty("tbs_core_version");
                        if (property == null) {
                            try {
                                bufferedInputStream2.close();
                            } catch (IOException e) {
                                TbsLog.i("TbsInstaller", "TbsInstaller--getTbsCoreInstalledVerInNolock IOException=" + e.toString());
                            }
                            return 0;
                        }
                        int parseInt = Integer.parseInt(property);
                        if (o == 0) {
                            o = parseInt;
                        }
                        try {
                            bufferedInputStream2.close();
                        } catch (IOException e2) {
                            TbsLog.i("TbsInstaller", "TbsInstaller--getTbsCoreInstalledVerInNolock IOException=" + e2.toString());
                        }
                        return parseInt;
                    } catch (Exception e3) {
                        e = e3;
                        bufferedInputStream = bufferedInputStream2;
                        TbsLog.i("TbsInstaller", "TbsInstaller--getTbsCoreInstalledVerInNolock Exception=" + e.toString());
                        if (bufferedInputStream != null) {
                            try {
                                bufferedInputStream.close();
                            } catch (IOException e4) {
                                TbsLog.i("TbsInstaller", "TbsInstaller--getTbsCoreInstalledVerInNolock IOException=" + e4.toString());
                            }
                        }
                        return 0;
                    } catch (Throwable th) {
                        th = th;
                        bufferedInputStream = bufferedInputStream2;
                        if (bufferedInputStream != null) {
                            try {
                                bufferedInputStream.close();
                            } catch (IOException e5) {
                                TbsLog.i("TbsInstaller", "TbsInstaller--getTbsCoreInstalledVerInNolock IOException=" + e5.toString());
                            }
                        }
                        throw th;
                    }
                }
                return 0;
            } catch (Throwable th2) {
                th = th2;
            }
        } catch (Exception e6) {
            e = e6;
        }
    }

    public int k(Context context) {
        int i2 = o;
        return i2 != 0 ? i2 : j(context);
    }

    public void l(Context context) {
        if (o != 0) {
            return;
        }
        o = j(context);
    }

    public boolean m(Context context) {
        return new File(r(context), "tbs.conf").exists();
    }

    public int n(Context context) {
        if (!x(context)) {
            return -1;
        }
        ReentrantLock reentrantLock = i;
        boolean tryLock = reentrantLock.tryLock();
        TbsLog.i("TbsInstaller", "TbsInstaller--getTbsCoreInstalledVer locked=" + tryLock);
        if (!tryLock) {
            b();
            return 0;
        }
        BufferedInputStream bufferedInputStream = null;
        try {
            try {
                File file = new File(r(context), "tbs.conf");
                if (!file.exists()) {
                    try {
                        if (reentrantLock.isHeldByCurrentThread()) {
                            reentrantLock.unlock();
                        }
                    } catch (Throwable th) {
                        TbsLog.e("TbsInstaller", "TbsRenameLock.unlock exception: " + th);
                    }
                    b();
                    return 0;
                }
                Properties properties = new Properties();
                BufferedInputStream bufferedInputStream2 = new BufferedInputStream(new FileInputStream(file));
                try {
                    properties.load(bufferedInputStream2);
                    bufferedInputStream2.close();
                    String property = properties.getProperty("tbs_core_version");
                    if (property == null) {
                        try {
                            bufferedInputStream2.close();
                        } catch (IOException e) {
                            TbsLog.i("TbsInstaller", "TbsInstaller--getTbsCoreInstalledVer IOException=" + e.toString());
                        }
                        try {
                            ReentrantLock reentrantLock2 = i;
                            if (reentrantLock2.isHeldByCurrentThread()) {
                                reentrantLock2.unlock();
                            }
                        } catch (Throwable th2) {
                            TbsLog.e("TbsInstaller", "TbsRenameLock.unlock exception: " + th2);
                        }
                        b();
                        return 0;
                    }
                    a.set(Integer.valueOf(Integer.parseInt(property)));
                    int intValue = a.get().intValue();
                    try {
                        bufferedInputStream2.close();
                    } catch (IOException e2) {
                        TbsLog.i("TbsInstaller", "TbsInstaller--getTbsCoreInstalledVer IOException=" + e2.toString());
                    }
                    try {
                        ReentrantLock reentrantLock3 = i;
                        if (reentrantLock3.isHeldByCurrentThread()) {
                            reentrantLock3.unlock();
                        }
                    } catch (Throwable th3) {
                        TbsLog.e("TbsInstaller", "TbsRenameLock.unlock exception: " + th3);
                    }
                    b();
                    return intValue;
                } catch (Exception e3) {
                    e = e3;
                    bufferedInputStream = bufferedInputStream2;
                    TbsLog.i("TbsInstaller", "TbsInstaller--getTbsCoreInstalledVer Exception=" + e.toString());
                    if (bufferedInputStream != null) {
                        try {
                            bufferedInputStream.close();
                        } catch (IOException e4) {
                            TbsLog.i("TbsInstaller", "TbsInstaller--getTbsCoreInstalledVer IOException=" + e4.toString());
                        }
                    }
                    try {
                        ReentrantLock reentrantLock4 = i;
                        if (reentrantLock4.isHeldByCurrentThread()) {
                            reentrantLock4.unlock();
                        }
                    } catch (Throwable th4) {
                        TbsLog.e("TbsInstaller", "TbsRenameLock.unlock exception: " + th4);
                    }
                    b();
                    return 0;
                } catch (Throwable th5) {
                    th = th5;
                    bufferedInputStream = bufferedInputStream2;
                    if (bufferedInputStream != null) {
                        try {
                            bufferedInputStream.close();
                        } catch (IOException e5) {
                            TbsLog.i("TbsInstaller", "TbsInstaller--getTbsCoreInstalledVer IOException=" + e5.toString());
                        }
                    }
                    try {
                        ReentrantLock reentrantLock5 = i;
                        if (reentrantLock5.isHeldByCurrentThread()) {
                            reentrantLock5.unlock();
                        }
                    } catch (Throwable th6) {
                        TbsLog.e("TbsInstaller", "TbsRenameLock.unlock exception: " + th6);
                    }
                    b();
                    throw th;
                }
            } catch (Throwable th7) {
                th = th7;
            }
        } catch (Exception e6) {
            e = e6;
        }
    }

    public boolean o(Context context) {
        TbsLog.i("TbsInstaller", "TbsInstaller--coreShareCopyToDecouple #0");
        File r = r(context);
        File q = q(context);
        try {
            com.tencent.smtt.utils.j.a(q, true);
            com.tencent.smtt.utils.j.a(r, q, new at(this));
            TbsShareManager.b(context);
            TbsLog.i("TbsInstaller", "TbsInstaller--coreShareCopyToDecouple success!!!");
            return true;
        } catch (Exception unused) {
            return false;
        }
    }

    public void p(Context context) {
        TbsLog.i("TbsInstaller", "TbsInstaller--cleanStatusAndTmpDir");
        ai.a(context).a(0);
        ai.a(context).b(0);
        ai.a(context).d(0);
        ai.a(context).a("incrupdate_retry_num", 0);
        if (TbsDownloadConfig.getInstance(context).mPreferences.getInt(TbsDownloadConfig.TbsConfigKey.KEY_DOWNLOADDECOUPLECORE, 0) != 1) {
            ai.a(context).b(0, -1);
            ai.a(context).a("");
            ai.a(context).a("copy_retry_num", 0);
            ai.a(context).c(-1);
            ai.a(context).a(0, -1);
            com.tencent.smtt.utils.j.a(u(context), true);
            com.tencent.smtt.utils.j.a(w(context), true);
        }
    }

    public File q(Context context) {
        File file = new File(context.getDir("tbs", 0), "core_share_decouple");
        if (file.isDirectory() || file.mkdir()) {
            return file;
        }
        return null;
    }

    public File r(Context context) {
        return b((Context) null, context);
    }

    public File s(Context context) {
        File file = new File(context.getDir("tbs", 0), "share");
        if (file.isDirectory() || file.mkdir()) {
            return file;
        }
        return null;
    }

    public File u(Context context) {
        File file = new File(context.getDir("tbs", 0), "core_unzip_tmp");
        if (file.isDirectory() || file.mkdir()) {
            return file;
        }
        return null;
    }

    File v(Context context) {
        File file = new File(context.getDir("tbs", 0), "core_unzip_tmp_decouple");
        if (file.isDirectory() || file.mkdir()) {
            return file;
        }
        return null;
    }

    File w(Context context) {
        File file = new File(context.getDir("tbs", 0), "core_copy_tmp");
        if (file.isDirectory() || file.mkdir()) {
            return file;
        }
        return null;
    }

    synchronized boolean x(Context context) {
        this.e++;
        if (this.h) {
            TbsLog.i("TbsInstaller", "getTbsInstallingFileLock success,is cached= true");
            return true;
        }
        FileOutputStream b2 = com.tencent.smtt.utils.j.b(context, true, "tbslock.txt");
        this.g = b2;
        if (b2 != null) {
            FileLock a2 = com.tencent.smtt.utils.j.a(context, b2);
            this.f = a2;
            if (a2 == null) {
                return false;
            }
            TbsLog.i("TbsInstaller", "getTbsInstallingFileLock success,is cached= false");
            this.h = true;
            return true;
        }
        return false;
    }
}
